﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Logic;
using Entities;

namespace Presentation
{
	public partial class InfoBasic : UserControl
	{
		public InfoBasic()
		{
			InitializeComponent();
		}

		public void Initialize(Movie entity)
		{
			if (checkedListBoxGenres.Items.Count == 0)
			{
				GenreBL gbl = new GenreBL();
				checkedListBoxGenres.Items.AddRange(gbl.List().ToArray());
			}

			FillData(entity);
		}

		public void FillData(Movie entity)
		{
			Tag = entity;

			textBoxTitle.Text = entity.Title;
			textBoxYear.Text = entity.Year.ToString();
			textBoxDirector.Text = entity.Director;
			textBoxTagline.Text = entity.TagLine;

			for (int i = 0; i < checkedListBoxGenres.Items.Count; i++)
			{
				checkedListBoxGenres.SetItemChecked(i, false);
				for (int j = 0; j < entity.Genres.Count; j++)
					if (checkedListBoxGenres.Items[i].ToString().Contains(entity.Genres[j].Name))
						checkedListBoxGenres.SetItemChecked(i, true);
			}

			ratingControlRating.SetRating(entity.Rating);

            listBoxLocation.DataSource = entity.VideoInfo.FileName.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
		}

		public Movie GetMovie()
		{
			Movie entity = (Movie)(Tag);

			entity.Title = textBoxTitle.Text.Trim();
			entity.Year = Convert.ToInt32(textBoxYear.Text.Trim());
			entity.Director = textBoxDirector.Text.Trim();
			entity.TagLine = textBoxTagline.Text.Trim();

			entity.Genres.Clear();

			for (int i = 0; i < checkedListBoxGenres.CheckedItems.Count; i++)
				entity.Genres.Add((Genre)(checkedListBoxGenres.CheckedItems[i]));

			entity.Rating = ratingControlRating.RatingValue;

			return entity;
		}
	}
}